package com.aistar.controller;

import com.aistar.model.bo.Result;
import com.aistar.model.dto.resume.ResumeInfoDTO;
import com.aistar.model.entity.*;
import com.aistar.service.resume.IEditService;
import com.aistar.service.resume.ILoadService;
import com.aistar.service.resume.IResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName: ResumeRestController
 * @author: Lushengjie
 * @date: 2021/9/26 15:47
 * @Description: TODO...本类用来演示:
 */
@Controller
@RequestMapping("/resume")
public class ResumeController {
    @Autowired
    private IResumeService resumeService;

    @Autowired
    private ILoadService loadService;


//    @GetMapping("/latest")
//    public void   latestResume(HttpServletRequest request, HttpServletResponse response) throws IOException {
//        HttpSession session = request.getSession();
//        Employee employee= (Employee)session.getAttribute("employee");
//        Integer employeeId = employee.getId();
//        Integer resumeId = resumeService.getLatestResumeId(employeeId);
////        System.out.println("即将转到页面：/resume/resume_make?resumeId="+resumeId);
//
////        return "redirect:/resume/resume_make?resumeId="+resumeId;
//        //return "redirect:/redirect/index?base=r1";
////        return new Result("200","成功",resumeId);
//        response.sendRedirect("/hire/resume/resume_make?resumeId="+resumeId);
//    }
      //  简历制作
    @GetMapping("/resume_make")
    public String resumeMake(HttpServletRequest request,Integer resumeId) {
//        System.out.println(resumeId);
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(resumeId);
        request.setAttribute("resume", resumeInfoDTO);

        return "/WEB-INF/resume/resume_index/resume_make.jsp";
    }


    //   简历预览
    @GetMapping("/resume_preview")
    public String resumePreview(HttpServletRequest request, Integer resumeId) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(resumeId);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_index/resume_preview.jsp";
    }

    //    简历下载
    @GetMapping("/resume_upload")
    public String resumeUpload() {
        return "/WEB-INF/resume/resume_index/resume_upload.jsp";
    }

    //个人信息编辑
    @PostMapping("/basic_edit")
    public String basicEdit(HttpServletRequest request, Integer id) {
        // 在这里就可以获取到简历的id
        // 根据简历id就可以获取到所有信息
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/basic_edit.jsp";
    }

    //个人信息展示
    @PostMapping("/basic_info")
    public String basicInfo(HttpServletRequest request, Integer id) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/basic_info.jsp";
    }

    //求职偏好编辑
    @PostMapping("/job_edit")
    public String jobEdit(HttpServletRequest request, Integer id) {

        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/job_edit.jsp";
    }

    //求职偏好信息展示
    @PostMapping("/job_info")
    public String jobInfo(HttpServletRequest request, Integer id) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/job_info.jsp";
    }
    /**
     * 根据教育经历id加载教育经历编辑
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/edu_edit_update")
    public String eduEditUpdate(HttpServletRequest request,Integer id){
        // 根据教育经历id获取教育经历信息
        Education education = loadService.loadEducationByEducationId(id);
        request.setAttribute("education",education);
        return "/WEB-INF/resume/resume_info/edu_edit.jsp";
    }

    //教育经历展示
    @PostMapping("/edu_info")
    public String eduInfo(HttpServletRequest request, Integer id) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/edu_info.jsp";
    }

    /**
     * 根据实习经历id加载教育经历编辑
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/intern_edit_update")
    public String internEditUpdate(HttpServletRequest request,Integer id){
        //根据实习经历id获取实习经历信息
        System.out.println("实习经历id"+id);
        Intern intern = loadService.loadInternByInternId(id);
        System.out.println(intern);
        request.setAttribute("intern",intern);
        return "/WEB-INF/resume/resume_info/intern_edit.jsp";
    }

    //实习信息展示
    @PostMapping("/intern_info")
    public String internInfo(HttpServletRequest request, Integer id) {
//        System.out.println("实习经历id"+id);
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/intern_info.jsp";
    }
    /**
     * 根据项目id加载教育经历编辑
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/project_edit_update")
    public String projectEditUpdate(HttpServletRequest request,Integer id){
        System.out.println(id);
        Project project = loadService.loadProjectByProjectId(id);
        System.out.println(project);
        request.setAttribute("project",project);
        return  "/WEB-INF/resume/resume_info/project_edit.jsp";
    }


    //项目信息展示
    @PostMapping("/project_info")
    public String projectInfo(HttpServletRequest request, Integer id) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/project_info.jsp";
    }

    /**
     * 根据获奖经历id加载教育经历编辑
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/award_edit_update")
    public String awardEditUpdate(HttpServletRequest request,Integer id){
        System.out.println(id);
        Award award = loadService.loadAwardByAwardId(id);
        System.out.println(award);
        request.setAttribute("award",award);
        return  "/WEB-INF/resume/resume_info/award_edit.jsp";
    }
    //获奖信息展示
    @PostMapping("/award_info")
    public String awardInfo(HttpServletRequest request, Integer id) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/award_info.jsp";
    }

    //个人总结编辑
    @PostMapping("/summary_edit")
    public String summaryEdit(HttpServletRequest request, Integer id) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/summary_edit.jsp";
    }

    //个人总结展示
    @PostMapping("/summary_info")
    public String summaryInfo(HttpServletRequest request, Integer id) {
        ResumeInfoDTO resumeInfoDTO = resumeService.loadResumeById(id);
        request.setAttribute("resume", resumeInfoDTO);
        return "/WEB-INF/resume/resume_info/summary_info.jsp";
    }

    // 教育经历添加页面加载
    @RequestMapping("/education_add")
    public String educationAdd(){
        return "/WEB-INF/resume/resume_info/edu_add.jsp";
    }
    //实习经历添加页面加载
    @RequestMapping("/intern_add")
    public String internAdd(){
        return "/WEB-INF/resume/resume_info/intern_add.jsp";
    }
    //项目经历添加页面加载
    @RequestMapping("/project_add")
    public String projectAdd(){ return "/WEB-INF/resume/resume_info/project_add.jsp"; }
    //获奖经历添加页面加载
    @RequestMapping("/award_add")
    public String awardAdd(){ return "/WEB-INF/resume/resume_info/award_add.jsp"; }

}
